package main

import (
	"fmt"
	"sync"
	"time"
)

func printMessage(msg string, wg *sync.WaitGroup) {
	if wg != nil {
		defer wg.Done()
	}
	for i := 0; i < 5; i++ {
		fmt.Println(msg, i)
		time.Sleep(200 * time.Millisecond)
	}
}

func main() {
	var wg sync.WaitGroup
	wg.Add(1)
	go printMessage("Goroutine", &wg)
	printMessage("Main", nil)
	wg.Wait()
}
